package com.gis.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

import com.gis.bean.UserLog;
import com.gis.util.JDBCUtils;

public class LogDao {
	QueryRunner qr = new QueryRunner(JDBCUtils.getC3p0DateSource());
	private static LogDao INSTANCE = new LogDao(); 
	private LogDao() {
		
	}
	
	public static LogDao getInstance() {
		return INSTANCE;
	}
	
	/**
	 * insert user's operate log
	 * @param userLog
	 * @return
	 */
	public int writeLog(UserLog userLog) {
		String sql = "insert into tb_log(username, url, operate_time, ip, params) values(?,?,?,?,?)";
		int i = 0;
		try {
			i = qr.update(sql, userLog.getUsername(), userLog.getUrl(), userLog.getOprateTime(), userLog.getIp(), userLog.getParams());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}
}
